﻿#if UNITY_EDITOR
using UnityEditor;
using UnityEditor.SceneManagement;
using UnityEngine;

public class StartSceneSetting : Editor
{
    [MenuItem("Tools/DefaultStartScene", true)]
    private static bool ValidatePlayModeUseStartScene()
    {
        Menu.SetChecked("Tools/DefaultStartScene", EditorSceneManager.playModeStartScene != null);
        return !EditorApplication.isPlaying;
    }

    [MenuItem("Tools/DefaultStartScene")]
    private static void UpdatePlayModeUseStartScene()
    {
        if (Menu.GetChecked("Tools/DefaultStartScene"))
        {
            EditorSceneManager.playModeStartScene = null;
        }
        else
        {
            if (EditorBuildSettings.scenes.Length == 0)
            {
                Debug.LogWarning("BuildSettings has no scenes");
                return;
            }

            var scene = AssetDatabase.LoadAssetAtPath<SceneAsset>(EditorBuildSettings.scenes[0].path);
            EditorSceneManager.playModeStartScene = scene;
        }
    }
}
#endif